For wireless fidelity (Wi-Fi, Wireless Fidelity) communication, two network communication manners are defined in the wireless local area network standard 802.11 formulated by the Institute of Electrical and Electronics Engineers (IEEE, Institute of Electrical and Electronics Engineers). The first communication manner is an infrastructure-based communication manner. In the first communication manner, a node is used as an access point (AP, Access Point), and another node except the node is used as a station (STA, Station). The access point provides an access service, and another node is connected to the access point and connects to a network by using the access point. The second communication manner is an independent basic service set (IBSS, independent basic service set) manner. In the second communication manner, each node is an equal node, and a connection is established between every two nodes.
In a subsequent development process, for further convenience of use, the Wi-Fi alliance (WFA, Wi-Fi Alliance) formulates the Wi-Fi Direct standard based on the 802.11 standard. Based on the 802.11 standard, the Wi-Fi Direct standard further defines how two nodes discover each other and how to establish a connection. Specifically, a node may randomly send a probe message on channels 1, 6, and 11 or listen to, on channels 1, 6, and 11, a probe message sent by another node. If a node detects a probe message sent by another node and replies, it may be considered that the two nodes have discovered each other. Then, the two nodes may negotiate with each other for roles of group owner (GO, Group Owner) and group client (Group Client). Generally, a node serving as a group owner is equivalent to an access point, and a node serving as a group client is equivalent to a station. The group client node may apply to the group owner node for association, and establish a connection.
However, the Wi-Fi Direct standard implements only discovery and connection on a Wi-Fi layer, and there is no uniform standard for a service layer over the Wi-Fi layer. To resolve this problem, the WFA further formulates the Wi-Fi Direct service (WFDS, Wi-Fi Direct Service) standard. In this standard, exchange of an upper layer service is standardized based on the Wi-Fi Direct, facilitating interworking between upper layer services of various manufacturers. For example, for a file transmission service, a uniform file transmission protocol may be used.
In this way, an upper layer application may perform data transmission of an upper layer service based on a Wi-Fi connection. The following uses an application session platform (ASP, Application Session Platform) as an example. The ASP may establish an ASP session based on a Wi-Fi connection (a peer to peer (P2P, Peer to Peer) connection is used in the prior art), and transmit upper layer service data by using the established ASP session.
Further, before an ASP session is established, service discovery first needs to be performed based on P2P. FIG. 1 is a flowchart showing that a node A and a node B perform service discovery by means of P2P on a Wi-Fi layer. After service discovery, a P2P network is established between the node A and the node B, and then, an ASP session is established over the P2P connection. FIG. 2 is a flowchart showing that the WFDS establishes an ASP session over a P2P connection.
As shown in FIG. 1, the node A represents an Advertiser in the WFDS, that is, a service provider, the node B represents a Seeker in the WFDS, that is, a service seeker, P2P represents a P2P module creating a connection on a Wi-Fi level, Service represents a service module, and ASP represents an ASP module. A process in which service discovery is performed by using P2P is as follows:
S101: A Service module of the node A sends an AdvertiseService message to an ASP module of the node A, so that the ASP module of the node A can receive a service request of another node.
S102: A Service module of the node B sends a SeekService message to an ASP module of the node B, to instruct the ASP module of the node B to query a specified service.
S103: The ASP module of the node B sends, by using a P2P module of the node B, a query message used to query the specified service.
S104: The ASP module of the node A receives the query message by using a P2P module of the node A, and determines that the service queried by the node B is a service that can be provided by the node A.
S105: The ASP module of the node A sends a query response message to the P2P module of the node B by using the P2P module of the node A.
After the service discovery process, the node B determines that the service provided by the node A is a service needed by the node B, so that a P2P connection may be established between the node A and the node B, and an ASP session is established based on the established P2P connection. As shown in FIG. 2, a process of creating an ASP session is as follows:
S201: A Service module of the node B sends a ConnectSessions indication of creating an ASP session to an ASP module of the node B.
S202: After receiving the ConnectSessions indication, the ASP module of the node B exchanges a VERSION message with an ASP module of the node A.
S203: After both communication parties acknowledge versions, the ASP module of the node B sends a REQUEST_SESSION message to the ASP module of the node A to request to establish an ASP session.
S204: After receiving the REQUEST_SESSION message, the ASP module of the node A exchanges request information of the node B with a Service module of the node A, and determines to prepare for a session.
S205: The ASP module of the node A sends a session adding ADDED_SESSION message to the ASP module of the node B, to agree with the node B on creating an ASP session.
S206: The Service module of the node A exchanges information about a port used by the node A with the ASP module of the node A, and determines the used port.
S207: The ASP module of the node A sends an allowed-port ALLOWED PORT message to the ASP module of the node B, to notify the node B that the node A already turns on the port.
S208: The ASP module of the node B sends a port report PortReport message to the Service module of the node B, to tell the Service module that the node A already turns on the port, exchanges information about a port used by the node B with the Service module of the node B, and determines the used port.
S209: The ASP module of the node B sends an allowed-port ALLOWED PORT message to the ASP module of the node A, to notify the node A that the node B already turns on the port.
S210: The ASP module of the node A sends a port report PortReport message to the Service module of the node A, to tell the Service module that the port of the node B is already turned on, and the node A and the node B may perform communication.
Then, a service connection may be established and service data may be transmitted between the Service module of the node A and the Service module of the node B.
As can be seen, in the prior art, upper layer service data transmission is based on a P2P connection. When a problem occurs on the P2P connection, for example, after a P2P connection is established between the node A and the node B, a distance between the node A and the node B is increasingly large, a signal of P2P connection is weaker, and even the connection is disrupted, an upper layer service based on the P2P connection may be interrupted. Consequently, data transmission of the upper layer service relies much on a bottom layer P2P connection based on which the upper layer service is established, and flexibility is poor.